﻿using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumTest
{
    [TestClass]
    public class TestProject
    {
        private ChromeDriver driver;
        string path;
        [TestInitialize]
        public void Setup()
        {
            string projectname = "seleniumtesting111";
            string path = Directory.GetCurrentDirectory().Substring(0, Directory.GetCurrentDirectory().LastIndexOf(@"seleniumtesting111") + projectname.Length);
            ChromeOptions incognito = new ChromeOptions();
            incognito.AddArgument("--incognito");
            driver = new ChromeDriver(path, incognito);
            string baseURL = "localhost:8080";
            driver.Navigate().GoToUrl(baseURL);
        }

        [TestCleanup]
        public void CleanUp()
        {
            driver.Quit();
        }

        [TestMethod]
        [Description("Test project list, and see if there is a project")]
        public void TestProjectListview()
        {
            driver.FindElement(By.LinkText("PROJEKTER")).Click();
            var elem = driver.FindElement(By.ClassName("projectBox")).Displayed;
            Assert.IsTrue(elem);
        }

        [TestMethod]
        [Description("Test if 'Boernefonden' is the " +
                     "organization that sponsor the detailed project of " +
                     "'Water in Mali'")]
        public void TestProjectDetailedView()
        {
            driver.FindElement(By.LinkText("PROJEKTER")).Click();
            driver.FindElementByPartialLinkText("Mali").Click();
            var logo = driver.FindElementById("organization-facts").FindElement(By.TagName("img")).Displayed;
            Assert.IsNotNull(logo);

        }
    }
}
